<template>
	<view class="u-p-28">
		<view class="card u-flex bg-white" v-for="(item,index) in list" :key="index">
			<view class="u-flex-1">
				<u-image width="114px" height="80px" :src="item.icon"></u-image>
			</view>
			<view class="info u-flex-1">
				<view class="u-font-18 color-3 font-weight">{{item.title}}</view>
				<view class="u-font-12 u-m-t-12 u-m-b-28 color-80">{{item.desc}}</view>
				<view class="btn" @click="goPublish(item)">发布</view>
			</view>
		</view>

		<u-tabbar :list="tabBar" active-color="#FFCF0B" inactive-color="#808080" :border-top="false"></u-tabbar>
	</view>
</template>

<script>
	import {
		tabBar
	} from '@/const';
	import {
		getIcons
	} from '@/api/common';
	import {
		getUserInfo
	} from '@/api/user';
	export default {
		data() {
			return {
				list: [],
				tabBar,
			}
		},
		onShow(){
			this.getIcons();
			const access_token = uni.getStorageSync('access_token');
			if (access_token) {
				this.getUserInfo();
			}
		},
		methods: {
			async getUserInfo() {
				const res = await getUserInfo();
				const count = res.data.message_unread;
				this.tabBar = tabBar.map((item, index) => {
					if (index === 3) {
						item.count = count;
					}
					return item;
				})
			},
			async getIcons() {
				const res = await getIcons();
				this.list = [{
					title: '领养信息',
					desc: '小可爱找新家',
					icon: res.data.adopt,
					page: '/pagesPublish/getInfo/getInfo',
				}, {
					title: '寻宠信息',
					desc: '时间就是生命',
					icon: res.data.find_pet,
					page: '/pagesPublish/findPet/findPet',
				}, {
					title: '寻主信息',
					desc: '寻找原主人',
					icon: res.data.find_master,
					page: '/pagesPublish/findSomeone/findSomeone',
				}]

			},
			goPublish(item) {
				const access_token = uni.getStorageSync('access_token');
				if (!access_token) {
					uni.showToast({
						title: '请先登录',
						icon: "none",
						mask: true,
					});
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/my/index'
						})
					}, 1500);
				} else {
					uni.navigateTo({
						url: item.page
					})
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.card {
		display: flex;
		border-radius: 10px;
		margin-bottom: 14px;
		padding: 50rpx 60rpx;
		justify-content: space-between;

		.info {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;

			.btn {
				width: 74px;
				height: 30px;
				font-size: 16px;
				color: #333;
				border-radius: 15px;
				background: #FFCF0B;
				text-align: center;
				line-height: 30px;
			}
		}
	}

	.font-weight {
		font-weight: 500;
	}
</style>
